﻿using Sunny.UI;
using System;
using CoreShop.Model;
using CoreShop.Library;
using Newtonsoft.Json;

namespace CoreShop.App
{

    /// <summary>
    /// 与POS前台的通讯）
    /// </summary>
    public partial class fpgPivotMonitor : UIPage
    {
        public fpgPivotMonitor()
        {
            InitializeComponent();
        }


        public void WriteLog(object obj)
        {
            this.Invoke(new Action(() =>
            {
                txtMessage.AppendText($"{DateTime.Now:HH:mm:ss}：{obj}\r\n");
            }));
        }

        public void WriteLog(PosPivotModel pivot)
        {
            string str = EnumHelper.GetDescByValue<GlobalEnumVars.SignalPivotCode>(pivot.code) + "->" + JsonConvert.SerializeObject(pivot);
            this.Invoke(new Action(() =>
            {
                if (txtMessage.Text.Length > 3000) txtMessage.Clear();
                txtMessage.AppendText($"{DateTime.Now:HH:mm:ss}：{str}\r\n");
            }));
        }

        
        private void fpgPivotMonitor_ReceiveParams(object sender, UIPageParamsArgs e)
        {
            var pivot = e.Value as PosPivotModel;
            switch (pivot.code)
            {
                case (int)GlobalEnumVars.SignalPivotCode.Code100:

                    break;
                default:
                    WriteLog(pivot);
                    break;
            }            
        }
    }
}